<template>
	<view class="login" :style="{height: wh + 'px'}">
		<view class="login-phone">
			<span>手 机 号 登 录</span>
		</view>
		<!-- 登录表单 -->
		<!-- 注意，如果需要兼容微信小程序，最好通过setRules方法设置rules规则 -->
		<u--form labelPosition="left" :model="userInfoObj" ref="userInfoRef">
			<u-form-item label="手机号" prop="userInfo.account" borderBottom>
				<u-icon name="phone" slot="label" color="#000" size="28"></u-icon>
				<u--input v-model="userInfoObj.userInfo.account" border="none" placeholder="请输入手机号"></u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item label="密码" prop="userInfo.password" borderBottom>
				<u-icon name="lock" slot="label" color="#000" size="28"></u-icon>
				<u--input v-model="userInfoObj.userInfo.password" type="password" placeholder="请输入密码" border="none"></u--input>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item>
				<u-button type="primary" text="登录" @click="loginFn"></u-button>
			</u-form-item>
		</u--form>
	</view>
	</view>
</template>

<script>
	import {
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				userInfoObj: {
					userInfo: {
						account: '',
						password: ''
					},
				},
				wh: '', // 当前屏幕可使用高度
			}
		},
		onLoad() {
			const sysInfo = uni.getSystemInfoSync()
			this.wh = sysInfo.windowHeight - 50
		},
		methods: {
			...mapMutations('loginModules', ['setToken']),
			async loginFn() {
				const {
					data
				} = await uni.$http.post('/v1/login_api', this.userInfoObj.userInfo)
				if (data.status !== 200) return uni.$showMsg()
				uni.showToast({
					title: '登录成功!',
					duration: 1500,
					icon: 'success'
				})
				this.setToken(data.jwt)
				uni.setStorageSync('jwtToken', JSON.stringify(data.jwt))
				uni.switchTab({
					url: '/pages/my/my'
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login {
		min-height: 100vh;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.login-phone {
		display: flex;
		align-items: center;
		height: 300rpx;
		font-size: 50rpx;
	}

	/deep/.u-form {
		width: 80%;

		.u-form-item__body__left {
			width: unset;
		}
	}
	/deep/.u-icon {
		margin-right: 15rpx !important;
	}
</style>
